﻿Imports System
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Data
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms


'Author: Petros Papadopoulos
'Date: 15/01/2014

Public Class Form1

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs) Handles MyBase.Load

        ncd1.SettingPort()
        ' setting the port
        ncd1.OpenPort()
        ' open the port
        If (Not ncd1.IsOpen) Then
            MessageBox.Show("Fail to Open Port!")
            Application.Exit()
        End If

        Check_Relay_Status()

    End Sub

    Private Sub Check_Relay_Status()

        Dim Relay_Status As Long
        Relay_Status = ncd1.ProXR.RelayBanks.GetStatus(0)
        If Relay_Status = 0 Then
            Label3.BackColor = Color.Red
            Label3.ForeColor = Color.Red
        Else
            If Relay_Status = 1 Then
                Label3.BackColor = Color.Green
                Label3.ForeColor = Color.Green
            Else
                MessageBox.Show("Can not Read the Status")
            End If
        End If

    End Sub

    Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click

        ncd1.ProXR.RelayBanks.TurnOnRelay(0)
        Check_Relay_Status()

    End Sub

    Private Sub Button2_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button2.Click

        ncd1.ProXR.RelayBanks.TurnOffRelay(0)
        Check_Relay_Status()

    End Sub

    Private Sub Button3_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button3.Click
        Try
            Dim value As Integer = ncd1.ProXR.AD8.Read8BitsValue(0)
            'return 8 bits value from channel 0
            ProgressBar1.Value = value * 100 / 255
            'set value to progress bar
            Label1.Text = String.Format("{0}/255", value)
            'show value in text
            'show voltage in text
            Label4.Text = String.Format("{0:F3}", value * 5 / 255)
        Catch ex As TimeoutException
            Label2.Text = ex.Message
        End Try

    End Sub

End Class
